colors =   Array('#555555','#c20','#0b0','#22f','#ea0','#0bb','#b0b','#000000');
colorshi = Array('#999999','#aa5555','#558855','#5555aa','#888855','#558888','#885588','#000000');
ranks = Array('Private', 'Private First Class', 'Corporal', 'Sergeant', 'Staff Sergeant', 'Sergeant First Class', 
		'Master Sergeant', 'Second Lieutenant', 'First Lieutenant', 'Captain', 'Major', 'Lieutenant Colonel', 'Colonel', 
		'Brigadier General', 'Major General', 'Lieutenant General', 'General', 'General of the Army');

noTransition = false;
ADSENSE = true;
STATIC_HOST = "http://flict.net/war/";
//STATIC_HOST="";
var JSID=-1;
BLACK_WIDTH = 0;
muted = Array('NOBODY','');
local_chairs = Array();
local_watchers = Array();
WINDOW_SCROLL=50;
playsound = 1;
afk = 0;
var tableInfoStr = "";
myColor = 0;
UA = 0;
IE6 = 0;
MAP_HEIGHT=360;
MAP_WIDTH=650;
map_width=0;
map_height=0;
table_size = 0;
cell_width=48;
cell_height=48;
var roll_disp_off = true;
START_TIME=13;
timer_seconds = 0;
//tablecount = [];
TNAME='';
round=1;
skinName = 'default';
var loadONCE = true;
first_resize=1;
var myTurn = false;
var timeleft = 20;
var gameinprogress=0;
var sound_effects_off = false;


chatlog = new Array('Welcome to <b>c</b>0<b>nflict</b>.<br>','');
statuslog = new Array('','');

    var whoami=0;
    var total_dice = 50;
    player_tot = [0,0,0,0,0,0,0];
    player_lan = [0,0,0,0,0,0,0];
    player_plu = [0,0,0,0,0,0,0];
    rainbowG = [0,0];
    diceG = [0,0];

mapstaron = "http://c0nflict.com/forum/templates/default/images/star_on.gif";
mapstaroff = "http://c0nflict.com/forum/templates/default/images/star_off.gif";

function rate_map(rating) {
	for (x=1;x<=rating;x++) {
	  document.getElementById('mapstar'+x).src = mapstaron;
	}	
	for (x=rating+1;x<=5;x++) {
	  document.getElementById('mapstar'+x).src = mapstaroff;	  
	}
}

function put_rating(rating) {
	Tracker.putRating(rating);
	rate_map(rating);
}

function toggleSound() {
	if (playsound == 1) {
		document.getElementById('Snd').innerHTML = 'Enable Sounds';
		playsound = 0;
	} else {
		playsound = 1;
		document.getElementById('Snd').innerHTML = 'Mute Sounds';
	}
}

function toggleAFK() {
	Tracker.toggleAFK(function(response) {
		if (response == 1) {
			if (afk == 1) {
				afk = 0;
				document.getElementById('afk').innerHTML = 'AFK';
			} else {
				afk = 1;
				document.getElementById('afk').innerHTML = 'I\'m back';
			}
		}
	});
}

function playSound(sound) {
if (sound_effects_off && !(sound=='startturn' || sound =='startgame')) return;
if (playsound==1)
        soundManager.play(sound);
}
function playerDeath(x) {
 if (parseInt(x)==parseInt(myColor)) {
   myColor=0;
   gameinprogress=0;
   document.getElementById('offturn_moves').innerHTML='';
   //timer_seconds=0;
 }
 playSound('playerdeath');
}
function handle_silently(message) {
 // sendStatus("<font size=.5em>"+message+"</font><br>");
}

function enableTableControls() {
  if (myColor>0) {
	document.getElementById('chair').innerHTML='Stand Up';
	  document.getElementById('tc_frame').className='';
	  //document.getElementById('chair').disabled=false;
	  if (gameinprogress==1) {
	  		if (myTurn==true) {
	  		  document.getElementById("tc_et_frame").className='';
	  		} else {
	  		  document.getElementById("tc_et_frame").className='hidden';
	  		}
	    	document.getElementById('pntxt').innerHTML='Offer Draw';
  	        document.getElementById("chair").innerHTML='Surrender';
		  	//document.getElementById('endturn').disabled=false;		  
//	  		document.getElementById('tc_et_frame').className='';
			if (tableRound>3) {
				//document.getElementById('gamestart_now').disabled=false;
		  		document.getElementById('tc_gs_frame').className='';
			} else {
				//document.getElementById('gamestart_now').disabled=true;
		  		document.getElementById('tc_gs_frame').className='hidden';
			}
	  } else {
  	        document.getElementById('pntxt').innerHTML='Play now';
		  	//document.getElementById('endturn').disabled=true;	
	  		document.getElementById('tc_et_frame').className='hidden';
		  	
	  }
  } else 
  {
  	if (gameinprogress==1) {
	  		//document.getElementById('chair').disabled=true;
		  	//document.getElementById('endturn').disabled=true;	
			//document.getElementById('gamestart_now').disabled=true;
			document.getElementById('tc_frame').className='hidden';

  	} else {
	  		document.getElementById('chair').innerHTML='Sit/Play';
	  		document.getElementById('pntxt').innerHTML='Play now';
	  		document.getElementById('chair').disabled=false;
		  	document.getElementById('tc_gs_frame').className='';
		  	document.getElementById('tc_et_frame').className='hidden';
		  	//document.getElementById('endturn').disabled=true;	
			//document.getElementById('gamestart_now').disabled=false;
			document.getElementById('tc_frame').className='';
  	}
  }
}

function set_play_now(color,state) {
	try {
	if (color==myColor)
	 document.getElementById('gamestart_now').checked = state;
	
	if (myColor > 0) {
		// Show/hide check icon
		if (state == true) {
			document.getElementById("user" + color + "playnow").innerHTML = '<img style="" src="images/tick.png" alt="Play Now">';
			document.getElementById("user" + color + "playnow").title = 'Play Now';
		} else {
			//if (/*gameinprogress==1 && */color==myColor && state==false)
				//document.getElementById('tc_gs_frame').className='hidden';
			document.getElementById("user" + color + "playnow").innerHTML = '';
		}
	}
	} catch (err) { handle_silently(err); }
}

function chairEvent() {
	tutorSatIn();
	//set_play_now(false);
	Tracker.chairEvent();
}
function setMyColor(x) {
	myColor = x;

  enableTableControls();
}
var ORIGINAL_PANEL_HEIGHT=0;
var OPERAWII = 0;
function size_controls() {

UA=1;
if (navigator.appVersion.indexOf("MSIE")!=-1) { 
UA = 0;
temp=navigator.appVersion.split("MSIE");
version=parseFloat(temp[1]);
//if (version<7) IE6=1;
}

doSidebar=false;
if (loadONCE) {
  ORIGINAL_PANEL_HEIGHT=(bh - (24+60+21*4));
  doSidebar=true;
  loadONCE = false;
  setTimeout("startTimerOne();",5000);
  if (navigator.appVersion.indexOf("Nintendo")!=-1) { 
  	OPERAWII = 1;
  }
   
}
bw = document.body.clientWidth;

bh = document.body.clientHeight;
  if (document.getElementById('cover').className=='') {
  document.getElementById('cover').style.height=bh;
  document.getElementById('cover').style.width=bw;
  if (!LOADING) {
  document.getElementById('register').style.top=(bh-260)/2+'px';
  document.getElementById('register').style.left=(bw-660)/2+'px';
  }}

if (bw<890) bw=890;
if (bh<531) bh=531;

if (first_resize!=1) {
   cwmod = 250;
	/*
   if (UA==0) {
		var boxes = document.getElementsByName("statbox");
		for (i=0;i<boxes.length;i++) {
			boxes[i].style.marginRight = -40px;
			boxes[i].style.marginTop   = -60px;
		}		
   }
   */
   if (ADSENSE) cwmod = 380; 
   cell_width=parseInt((bw-cwmod)/(map_width+2));
   cell_height=parseInt((bh-275)/map_height);
   if (cell_height<cell_width) cell_width=cell_height;
   if (cell_width<cell_height) cell_height=cell_width;
   if (cell_width>128) {
     cell_width=128;
     cell_height=128;
   }
   MAP_WIDTH=(2+map_width) * (cell_width+BLACK_WIDTH*UA) + 4;  //was +2
   if (IE6==1)
   MAP_WIDTH=(map_width) * (cell_width+BLACK_WIDTH*UA) + 4; // was +2
   MAP_HEIGHT=map_height * (cell_height+BLACK_WIDTH) + 4;  //was +2

 draw_map(TNAME,JSID,-1,gameinprogress);
 random_color(rainbowG,diceG);
}
first_resize=0;

document.getElementById('countdown').style.top = (bh - 185)+'px';
document.getElementById('offturn_moves').style.top = (bh - 193)+'px';
/*
document.getElementById('tableinfo').style.left = 20+(((bw - 218))-MAP_WIDTH)/2+'px';
document.getElementById('tableinfo').style.top =(20+(((bh - 208))-MAP_HEIGHT)/2+MAP_HEIGHT)+'px';
document.getElementById("ads").style.left = '3px';
document.getElementById("ads").style.top = '50px';
document.getElementById("ads").style.height = (bh-50)+'px';
document.getElementById("ads").style.width = '300px';
*/
adjust=0;
if (ADSENSE) {
/*SETAHTML ADSENSE ADS REMOVE HERE */
//if ((parseInt(bw)-parseInt(MAP_WIDTH)-200) > 145) {
  if (((parseInt(bw) - 218)-parseInt(MAP_WIDTH))/2<250) {
  adjust = 140-((parseInt(bw) - 218)-parseInt(MAP_WIDTH))/2;
  }
//}
setAHTML('8464056649',bh-50,250);
}
if (adjust<0) adjust=0;
//	firefox specific
if (UA==1)
{
document.getElementById("sidebar").style.height = (bh - 24)+'px';
document.getElementById("sidebar").style.position = 'absolute';
document.getElementById("sidebar").style.top = '10px';
document.getElementById("sidebar").style.left = (bw-194) +'px';
//document.getElementById("roster").style.height = (bh - 324)+'px';
document.getElementById("roster").style.height = (bh - (24+60+21*4))+'px';  //was all 178
//document.getElementById("friendslist").style.height = (bh-(24+60+21*4))+'px';
//document.getElementById("buddylist").style.height = (bh-(24+60+21*4))+'px';
//$(document).ready( function () {
//dwr.util.removeAllOptions("tbanner");

document.getElementById("sbac4").style.height='0px';
document.getElementById("sbac5").style.height='0px';
document.getElementById("sbac6").style.height='0px';
//document.getElementById("sbac1").onclick = null;
document.getElementById("sbac3").onclick = null;
document.getElementById("tbanner").onclick = null;
document.getElementById("fbanner").onclick = null;
document.getElementById("roster").style.height=(bh-(24+60+168+21*3)-0)+'px';
//document.getElementById("sbac").style.height=(bh-(24))+'px';
document.getElementById("sbac").style.height=168+21*3+'px';

//ORIGINAL_PANEL_HEIGHT-= ORIGINAL_PANEL_HEIGHT-(bh - (24+60+21*4));
	//		doSidebar=false;
			$('#sbac').Accordion(
				{
					headerSelector	: 'dt',
					panelSelector	: 'dd',
					activeClass		: 'myAccordionActive',
					hoverClass		: 'myAccordionHover',
					panelHeight		: 168,//(bh - (24+60+21*4)), //was 168
					speed			: 300
				}
			);
//			});

//document.getElementById("sbac").style.height = (bh-(24+60));

document.getElementById("chatroom").style.width = (bw - 218)+'px';
neww = bw-218;
document.getElementById("status").style.width = neww*.37+'px';
document.getElementById("chat").style.width = neww*.6+'px';


document.getElementById("phrase").style.width = (bw - 310)+'px';
document.getElementById("chatroom").style.top = (bh - 172)+'px';
document.getElementById("tablecontrols").style.left = (bw - 495)+'px';
document.getElementById("offturn_moves").style.left = (bw - 405)+'px';
document.getElementById("game").style.left = adjust+(((bw - 218))-MAP_WIDTH)/2+'px';
document.getElementById("game").style.top = 12+(((bh - 178))-MAP_HEIGHT)/2+'px';

} 
//MSIE :(
if (UA==0) {
//document.getElementById("tablecontrols").style.top = (bh - 200)+'px';
document.getElementById("tablecontrols").style.left = (bw - 490)+'px';
document.getElementById("offturn_moves").style.left = (bw - 400)+'px';
document.getElementById("header").style.position = 'absolute';
document.getElementById("header").style.left = '0px';
document.getElementById("header").style.top = '0px';
document.getElementById("sidebar").style.height = (bh - 25)+'px';
document.getElementById("sidebar").style.position = 'absolute';
document.getElementById("sidebar").style.top = '10px';
document.getElementById("sidebar").style.left = (bw-194) +'px';
//document.getElementById("roster").style.height = (bh - 324)+'px';
document.getElementById("roster").style.height=(bh-(24+60+168+21*3)-0)+'px';
//document.getElementById("roster").style.height = (bh - 300)+'px';
//document.getElementById("friendslist").style.height = (bh - 300)+'px';
//document.getElementById("buddylist").style.height = (bh - 300)+'px';
/*
document.getElementById("sbac").style.height=(bh-(24))+'px';
document.getElementById("sbac2").style.height=(bh-(24+60+21*4))+'px';
document.getElementById("sbac4").style.height='0px';
document.getElementById("sbac5").style.height='0px';
document.getElementById("sbac6").style.height='0px';
document.getElementById("sbac1").onclick = null;
document.getElementById("sbac3").onclick = null;
document.getElementById("tbanner").onclick = null;
document.getElementById("fbanner").onclick = null;
*/
//$(document).ready( function () {
document.getElementById("sbac").style.height=168+21*3+'px';
			$('#sbac').Accordion(
				{
					headerSelector	: 'dt',
					panelSelector	: 'dd',
					activeClass		: 'myAccordionActive',
					hoverClass		: 'myAccordionHover',
					panelHeight		: 168,
					speed			: 300
				}
			);
//			});

document.getElementById("chatroom").style.width = (bw - 218)+'px';
neww = bw-218;
document.getElementById("status").style.width = neww*.37+'px';
document.getElementById("chat").style.width = neww*.6+'px';

document.getElementById("phrase").style.width = (bw - 310)+'px';
document.getElementById("chatroom").style.top = (bh - 170)+'px';
document.getElementById("game").style.left = adjust+(((bw - 218))-MAP_WIDTH)/2+'px';
document.getElementById("game").style.top =  (12+((bh - 185)-MAP_HEIGHT)/2-60)+'px';

}
}
function prep_map (w,h)
 //calculate total map size, and set its sizes to global vars for resize.
 {
   map_width = w;
   map_height= h;
   table_size = w * h;

   war_matrix = new Array(table_size);
   for (x = 0; x < table_size; x++) { war_matrix[x] = -1; }
   size_controls();
 }

function draw_map (tablename,jsid,this_color,map_running)
//draw map construct
  {
  sc = 0;
  //if (JSID==jsid) return;
  clearTurnNums();
  if (this_color!=-1) 
    myColor=this_color;
  gameinprogress=map_running;
  
  JSID = jsid;
  if (LOADING)
  document.getElementById('loadingstatus').innerHTML+='Drawing map.. '; 
    if (tablename==null) tablename=TNAME;
    setCurrentTableStr(JSID);
  	timeleft=0;
  	timer_seconds=0;
    TNAME=tablename;
    document.getElementById("tablename").innerHTML=TNAME;
	
    document.getElementById("game").style.width = (2+map_width) * (cell_width+BLACK_WIDTH*UA) + 4+ "px";
    if (IE6==1)
    document.getElementById("game").style.width = (map_width) * (cell_width+BLACK_WIDTH*UA) + 4+ "px";
    document.getElementById("game").style.height = map_height * (cell_height+BLACK_WIDTH*UA) + 4+ "px";
    var html_div = "";
    var colnum = 1;
    var rownum = 1;
    var cellleft = 0;
    var celltop = 0;   
    var cn2 = (cell_height+BLACK_WIDTH*UA)+BLACK_WIDTH*UA;  //was +2 both
    var cn = cell_height;
    var fnw = eval(parseInt(Math.min(cell_width,cell_height) / 2));
    // -2;
    for (x = 0; x < table_size; x++)
    {
	cmap_width=map_width;
	if (IE6!=1) cmap_width=map_width+2;
        if (colnum > cmap_width) { colnum = 1; rownum++; }
        celltop = (rownum-1)*cn2;
        cellleft = (colnum-1)*cn2;
	bl="";
	br="";
	if (IE6!=1) {
	if (colnum==1) {
		y = x+map_width-1;
		html_div += '<div class="cdie" onClick="wowza('+y+')" id="c'+y+'" style="cursor: pointer; width:'+cell_width+'px; left:'+cellleft+'px; top:'+celltop+'px; height:'+cell_height+'px; line-height:'+cell_height+'px; text-decoration:none; font-family:verdana;font-size:'+fnw+'px; z-index:2; -moz-user-select:none; "><img class="dimg" src="'+STATIC_HOST+'images/0.png" height="'+(cn)+'" width="'+(cn)+'" name="imc'+y+'" id="imc'+y+'"></div>';
	colnum++;
        celltop = (rownum-1)*cn2;
        cellleft = (colnum-1)*cn2;

	}
	}

		html_div += '<div class="die" onClick="wowza('+x+')" id="'+x+'" style="cursor: pointer; width:'+cell_width+'px; left:'+cellleft+'px; top:'+celltop+'px; height:'+cell_height+'px; line-height:'+cell_height+'px; text-decoration:none; font-family:verdana;font-size:'+fnw+'px; z-index:2; -moz-user-select:none; "><img class="dimg" src="'+STATIC_HOST+'images/0.png" height="'+(cn)+'" width="'+(cn)+'" name="im'+x+'" id="im'+x+'"></div>';
	if (IE6!=1) {
	if (colnum==map_width+1) {
	colnum++;
        celltop = (rownum-1)*cn2;
        cellleft = (colnum-1)*cn2;
		y = x-map_width+1;
		html_div += '<div class="cdie" onClick="wowza('+y+')" id="c'+y+'" style="cursor: pointer; width:'+cell_width+'px; left:'+cellleft+'px; top:'+celltop+'px; height:'+cell_height+'px; line-height:'+cell_height+'px; text-decoration:none; font-family:verdana;font-size:'+fnw+'px; z-index:2; -moz-user-select:none; "><img class="dimg" src="'+STATIC_HOST+'images/0.png" height="'+(cn)+'" width="'+(cn)+'" name="imc'+y+'" id="imc'+y+'"></div>';
	}
	}
       colnum++;

     }
     enableTableControls();
     document.getElementById("game").innerHTML = html_div;
}

localDepress = -1;


keepLastAttack = true;

undepressOwnColor = true;

function wowza(x) {
   pfoc();
  //square depressed fuction
    //if (myColor==0) return;
	if (rainbowG[x]==myColor && localDepress==-1 && myTurn && diceG[x]>1) {

	} else if (undepressOwnColor && localDepress!=x && rainbowG[x]==myColor && localDepress!=-1 && myTurn) {
	        Tracker.wowza(localDepress);
		setTimeout("Tracker.wowza("+x+");",100);
		return;
        }
    //if (myTurn || myColor>0)
	Tracker.wowza(x);
}
function random_color(rainbow,dices) {

player_tot = Array(0,0,0,0,0,0,0);
player_lan = Array(0,0,0,0,0,0,0);
player_plu = Array(0,0,0,0,0,0,0);
diceG = dices;
rainbowG = rainbow;
for (x = 0; x < table_size && x < rainbow.length; x++) {
        if (rainbow[x]==7 || rainbow[x]==-1) {
	blacken(x);
	if (x%map_width==0 || x%map_width==map_width-1) blacken('c'+x);

	} else {
        if (rainbow[x] >= 0 && rainbow[x]<=6) {
	try {
	document.getElementById(x).style.backgroundColor = colors[rainbow[x]];
	if (IE6!=1)
	if (x%map_width==0 || x%map_width==map_width-1) document.getElementById('c'+x).style.backgroundColor = colors[rainbow[x]];
	} catch (err) { handle_silently(err); return;}
	

	player_lan[rainbow[x]]++;
	player_tot[rainbow[x]]+=dices[x];
	} }
	if (dices[x]!=0) {
        if (IE6==1) {
		document.getElementById(x).innerHTML = dices[x]; } else {
		document.getElementById(x).style.backgroundImage = 'none';
	    	dImg(x,dices[x]);
		}
	}

}
  for (usr=1;usr<7;usr++) {
document.getElementById("user"+usr+"dice").innerHTML=player_tot[usr]+"&#x25cf;";	   
document.getElementById("user"+usr+"land").innerHTML=player_lan[usr]+"&#x25a0;";	   
  }

if (LOADING) {
  LOADING=false;
  setTimeout("hideloading();",1200);
  try {
  _uacct = "UA-2738908-5";
  urchinTracker();
  } catch (err) { handle_silently(err); }
}
}

function dImg(divid, numr) {
  //set dice image to map square
   try {
   if (IE6!=1)
   if (divid%map_width==0 || divid%map_width==map_width-1) dImg('c'+divid,numr);
   } catch (err) {}
   try {
    //dir = '';
    //if (skinName!='default') dir = skinName + '/';
	//document.getElementById(divid).innerHTML = '<img class="dimg" height='+(cell_height-2)+'; width='+(cell_width-2)+' src="images/'+dir+numr+'.png" alt="'+numr+'">';
	//document.images['im'+divid].src=dimgc[numr].src;//.src; 
	document.getElementById('im'+divid).src=dimgc[numr].src; 
//	document.getElementById('im'+divid).src=eval("dimgc"+numr+".src"); 
	//document.getElementById('im'+divid).src='image	s/'+dir+numr+'.png'; 
	//document.getElementById('im'+divid).alt=numr;
	document.images['im'+divid].alt=numr;
	} catch (err) {
		//alert(err);
		handle_silently(err);
	}
}

function depress_square(x,y) {
  try {
  //depress mapsquare -- reversed from tracker
       playSound('click');
	   if (y==myColor) localDepress=x;
	   document.getElementById(x).style.backgroundColor=colorshi[y];
	   document.getElementById(x).style.borderColor = colors[y];
	   document.getElementById(x).style.borderWidth = 3;
	   document.getElementById(x).style.borderStyle = 'inset';
	   if (y==myColor)
	   	tutorSquareDepressed();
   } catch (err) { handle_silently(err); }
}

function undepress_square(x,y) {
	try {
	   localDepress=-1;
		if (IE6!=1)
   		if (x%map_width==0 || x%map_width==map_width-1) {
	   document.getElementById('c'+x).style.backgroundColor=colors[y];
		}
	   document.getElementById(x).style.backgroundColor=colors[y];
           document.getElementById(x).style.borderWidth = 1;
           document.getElementById(x).style.borderColor = 'black';
           document.getElementById(x).style.borderStyle = 'solid';
             } catch (err) { handle_silently(err); }

}

function get_rank_id(rating) {
	id = Math.floor(rating / 60.0);
	if (id > 17) id = 17;
	return id;
}

function is_muted(person) {
	for (i = 0; i < muted.length; i++) {
		if (person == muted[i]) {
			return true;
		}
	}
	
	return false;
}

function chair_roster(x, person, rating) {
	//draw the roster -- x = color, person = name, rating = elo
	if (person == '') {
		document.getElementById("user" + x).className = 'hidden';
		document.getElementById("user" + x).style.display = 'none';
		document.getElementById("user" + x + "name").innerHTML = '';
		document.getElementById("user" + x + "rank").innerHTML = '';
	} else {
		document.getElementById("user" + x).style.display = '';
		document.getElementById("user" + x).className = "user" + x;
		id = get_rank_id(rating);
		
//		if (afk == 1) {
//			document.getElementById("user" + x + "name").innerHTML = '<span style="AI" alt="' + rating + " / " + ranks[id] + '">AFK</span><br>' + person;
//		} else {
			imgx = STATIC_HOST + 'images/rank/e' + id + 'sm.gif';
			document.getElementById("user" + x + "name").innerHTML = '<img style="z-index: 99; margin-bottom: -80px; margin-left: 48px; float: left;" src="' + imgx + '" alt="' + rating + " / " + ranks[id] + '">' + person;
//		}
		
		document.getElementById("user" + x + "name").title = "Rating: " + rating + " / " + ranks[id];
		
		if (is_muted(person))
			set_chair_mute(x);
		else
			unset_chair_mute(x);  
	}
	
	//set_play_now(document.getElementById('gamestart_now').checked);
}

function dispmsg(msg1,msg2,widthct,timo) {
  //use rolldisp div to show a message 

  if (roll_disp_off) return;

  dice_speed = 180;
  if (IE6==1) return;
  var disp = document.getElementById("rolldisp");
  var disaf = document.getElementById("rollattacker");
  var disdf = document.getElementById("rolldefender");
  ct = 0;
  width = widthct;
  disp.style.width = width+'px';
  disp.style.height = '170px';
  var game_left = (document.body.clientWidth-(widthct))/2;
  var game_top = parseInt(document.getElementById("game").style.top);
  var game_width = document.getElementById("game").style.width;
  disaf.style.color='#eeeeee';
  disdf.style.color='#eeeeee';
  disaf.style.top='0px';
  disaf.style.left= '0px';
  disdf.style.top='10px';
  disdf.style.left= '0px';
  disaf.style.textAlign='center';
  disdf.style.textAlign='center';
  disp.style.left = game_left + 'px';
  disp.style.top = (game_top - 275)+'px';
  disp.className='';
  disp.style.opacity='0.8';
  celltop=0;
  cellleft=0;
  colnum=0;
  rownum=0;
  html_div2 = msg2;
  html_div1 = msg1;
  disaf.innerHTML=html_div1;
  disdf.innerHTML=html_div2;
  setTimeout("document.getElementById('rolldisp').className='hidden'",timo);
}

function set_player_info(person, rating) {
	if (person == '') {
		document.getElementById("player_info_rank").innerHTML = '';
		document.getElementById("player_info_name").innerHTML = '';
		document.getElementById("player_info_rating").innerHTML = '';
	} else {
		id = get_rank_id(rating);
		imgx = STATIC_HOST + 'images/rank/e' + id + 'sm.gif';
		document.getElementById("player_info_rank").innerHTML = '<img style="" src="' + imgx + '" title="' + ranks[id] + '"/>';
		document.getElementById("player_info_name").innerHTML = person;
		document.getElementById("player_info_rating").innerHTML = 'Rating: ' + rating;
	} 
}

function remove_watcher(person) {

}

function set_chair_mute(x) {
	document.getElementById("user" + x + "mute").innerHTML = '<img style="" src="images/sound_mute.png" alt="Player muted">';
}

function unset_chair_mute(x) {
	document.getElementById("user" + x + "mute").innerHTML = '';
}

function set_watcher_mute(x) {
	document.getElementById("watcher" + x + "mute").innerHTML = '<img style="" src="images/sound_mute.png" alt="Player muted">';
	document.getElementById("watcher" + x + "mute").className = 'unrp';
}

function unset_watcher_mute(x) {
	document.getElementById("watcher" + x + "mute").innerHTML = '';
	document.getElementById("watcher" + x + "mute").className = 'hidden';
}

function add_watcher(person, x) {
	local_watchers.push(person);

	document.getElementById("rosterothers").innerHTML += '<span class="hidden" id="watcher' + x + 'mute"></span>';
	document.getElementById("rosterothers").innerHTML += '<div onclick="ddm_replace(this, event, menu_tm, \'120px\')" class="user">' + person + '</div>';
	
	if (is_muted(person))
		set_watcher_mute(x);
}

function setSinglePlayerInfo(newinfo) {
 	document.getElementById("tableinfo").innerHTML=createTableInfo(newinfo);
}
 
function setCurrentTableStr(thistab) {
 tables = tableInfoStr;
 for (x=0;x<tables.length;x+=6) {
    if (thistab==tables[x+2]) {
 		document.getElementById("tableinfo").innerHTML=createTableInfo(tables[x+4]);
 	}
   //if (document.getElementById("tablename").innerHTML==tables[x]) {
   //alert(thistab+' '+tables[x]);
 	//	document.getElementById("tableinfo").innerHTML=createTableInfo(tables[x+4]);
  //}   
 }

}

function push_tables(tables) {
  if (LOADING)
  document.getElementById('loadingstatus').innerHTML+='Getting table information.<br>';
  tableInfoStr = tables;
  //render table list tables is a one dimensional array, in the form [name, #seated, tableid, repeat..]

 tablesHTML = "";
 
 for (x = 0; x < tables.length; x += 6) {
    tablesHTML += '<div class="user">';
    tbl_name = tables[x];
    tbl_player_counts = tables[x + 1];
    tbl_jsid = tables[x + 2];
    tbl_status = tables[x + 3];
    tbl_params = tables[x + 4];
    tbl_elo = tables[x + 5];

    id = Math.floor(parseInt(tbl_elo) / 60.0);
	if (id > 17) id = 17;
 	imgx = STATIC_HOST + 'images/rank/t' + id + 'sm.gif';
    IMGSTR = '<img class="utrank" src="' + imgx + '" title="' + tbl_elo + '" alt="' + tbl_elo + '">';
    if (tbl_status == 2)
    	color = '#555';
    else
    	color = '#ccc';
    	
    tablesHTML += '<div id="table' + tbl_jsid + '" class="utable" title="' + createTableTip(tbl_params);
    tablesHTML += '" style="color: ' + color + ';  float: left;" onClick="switchBoards(' + tbl_jsid + ',\'' + tbl_name + '\')">';
    tablesHTML += IMGSTR + tbl_name + '</div><div class="unr2" id="tct' + tbl_jsid + '">' + tbl_player_counts + '</div>';
    
    tablesHTML+='</div>';
    if (document.getElementById("tablename").innerHTML == tbl_name) {
 		document.getElementById("tableinfo").innerHTML=createTableInfo(tbl_params);
 	}
 }
 document.getElementById("friendslist").innerHTML=tablesHTML;
/*$('.utable').ToolTip(
	{
		className: 'inputsTooltip',
		//position: 'mouse',
		delay: 0
	}
);*/
}
function pfoc() {
  try {
  document.getElementById('phrase').focus();
  } catch (err) {} 
}
function switchBoards(it,tablename) {
  if (it==JSID) return;
  //JSID=it;
  document.getElementById('loadingstatus').innerHTML='Changing table..<br>';
  if (myColor<=0) {
  	//showloading();
  //setCurrentTableStr(JSID);
    gameinprogress=0;
  Tracker.switchBoards(parseInt(it));
  tutorTableChanged();
  }
  pfoc();
}
function change_tc(tableid, count) {
  try {
  	document.getElementById("tct" + tableid).innerHTML = count;
  } catch (err) { handle_silently(err); }
}

function push_roster(chairs,watchers) {
 // chairs and watchers are both arrays, watchers only names, chairs is defined in chair_roster
 xd = 0;
 local_chairs = new Array(0);
 for (x=1;x<7;x++) {
	chair_roster(x,'',0);
  }
 for (x=0;x<chairs.length;x+=2) {
  	xd++;
	chair_roster(xd,chairs[x],chairs[x+1]);
	local_chairs.push(chairs[x]);
 }

 document.getElementById("rosterothers").innerHTML='';
 local_watchers = new Array(0);
 for (x=0;x<watchers.length;x++) {
	add_watcher(watchers[x], x);
 }
 tc_roster(tc_newturn);
 /*$('.unl').ToolTip(
	{
		className: 'inputsTooltip',
		//position: 'mouse',
		delay: 20
	}
);*/

}
var BOUNCE_OFF = false;
function shake(attacker,defender) {
	if (BOUNCE_OFF) return;
  if (attacker-defender==1 || attacker-defender==-1) {
      //shake left/right
 	$('#'+attacker).Shake(3);
  } else { //shake up/down
 	$('#'+attacker).Bounce(40);
 
  }
}
function restack_dice(jsidcheck,aryofdice) {
if (parseInt(JSID)!=parseInt(jsidcheck)) return;
  // array of form [coordinate, total_dice, repeat..]
if (aryofdice.length==0) return;
atr = 0;
usr = rainbowG[aryofdice[0]];
rans=0;
for (x=0;x<aryofdice.length;x+=2) {
  player_tot[rainbowG[aryofdice[x]]]+=aryofdice[x+1]-diceG[aryofdice[x]];
  atr+=aryofdice[x+1]-diceG[aryofdice[x]];
  rans+= Math.random()*20;
  oldamt = diceG[aryofdice[x]];
  diceG[aryofdice[x]]=aryofdice[x+1];
        

if (IE6==1) document.getElementById(aryofdice[x]).innerHTML=aryofdice[x+1];
else {
	try {
        document.getElementById(aryofdice[x]).style.backgroundImage = 'none';
        setTimeout("dTransition("+aryofdice[x]+","+oldamt+","+aryofdice[x+1]+");",rans);
	} catch (err) { handle_silently (err); return; } 
  }
 if (usr==myColor)
 tutorGotRestack(atr);
}
try {
if (usr>0)
document.getElementById("user"+usr+"dice").innerHTML=player_tot[usr]+"&#x25cf;";	   
 } catch (err) { handle_silently(err); }
}


function refresh_squares(jsidcheck,x,y,xcolor,ycolor,xdice,ydice,attackary,defendary) {
  if (JSID!=jsidcheck) return;
  oldx= diceG[x];
  oldy= diceG[y];

  if (attackary.length>=1) {
  	displayroll(xcolor,rainbowG[y],diceG[x],diceG[y],attackary,defendary);
  }
  if (xcolor==myColor) {
    z=0;
    if (xcolor==ycolor) z=1;
    tutorAttackMade(z);
  }
  if (xcolor==currentColor)
	  startTimer(START_TIME);
	  //ADDED attackary==[] here for OFFTURN
	   if (ycolor!=rainbowG[y] || attackary==[]) {
		//rainbowG[y] lost the defend 

		if (keepLastAttack && myTurn) Tracker.wowza(y);
		player_tot[rainbowG[y]]-=diceG[y];

		//for partial attack
		player_tot[rainbowG[x]]+=(xdice-diceG[x]);
		player_tot[rainbowG[x]]+=(ydice);

		player_lan[rainbowG[y]]--;
		player_lan[rainbowG[x]]++;
		diceG[y]=ydice;
		diceG[x]=xdice;
	        playSound('click');

if (rainbowG[y]>0) {
try {
document.getElementById("user"+rainbowG[y]+"dice").innerHTML=player_tot[rainbowG[y]]+"&#x25cf;";	   
document.getElementById("user"+rainbowG[y]+"land").innerHTML=player_lan[rainbowG[y]]+"&#x25a0;";	   
} catch (err) { handle_silently(err); }
}
	   } else if (xdice!=diceG[x]) {
		//rainbowG[x] lost the attack
		player_tot[rainbowG[x]]+=xdice-diceG[x];
		player_tot[rainbowG[y]]+=ydice-diceG[y];
		diceG[x]=xdice;
		diceG[y]=ydice;
	        playSound('lossattack');
	   }
	   try {
	   document.getElementById("user"+rainbowG[x]+"dice").innerHTML=player_tot[rainbowG[x]]+"&#x25cf;";	   
	   document.getElementById("user"+rainbowG[x]+"land").innerHTML=player_lan[rainbowG[x]]+"&#x25a0;";
	   } catch (err) {handle_silently(err); }	   
	   undepress_square(x,xcolor);
	   undepress_square(y,ycolor);
	   rainbowG[x]=xcolor;
	   rainbowG[y]=ycolor;
        if (IE6==1) {
	   document.getElementById(x).innerHTML=xdice;
	   document.getElementById(y).innerHTML=ydice;
} else {

	dTransition(x,oldx,xdice);
        dTransition(y,oldy,ydice);	

	document.getElementById(y).style.backgroundImage = 'none';

//	document.getElementById(x).style.backgroundPosition = 'center';
//	document.getElementById(y).style.backgroundPosition = 'center';

}
}
timeStamp = false;
lastMessage = "";
function sendChat(message) {
  lpushdown = false;
  drx = 0;
  if (document.getElementById('chat').style.pixelHeight) drx=document.getElementById('chat').style.pixelHeight;
  else drx = document.getElementById('chat').offsetHeight;
  if (parseInt(document.getElementById('chat').scrollHeight)-  parseInt(document.getElementById('chat').scrollTop) <= parseInt(drx)+50) {
    lpushdown = true;
  }
  //sendStatus(parseInt(document.getElementById('chat').scrollHeight)+" " + parseInt(document.getElementById('chat').scrollTop) +" "+ parseInt(document.getElementById('chat').offsetHeight)+"<br>");
  
  ary = message.split(':');
  pushchatlog(ary[1]);
  
  	strname = ary[0].replace(/(<([^>]+)>)/ig,""); 
  	if (is_muted(strname)) return;
  	
  fmtmsg = message+'';
  stamp="";
  if (timeStamp) {
  var today=new Date();
  var h=today.getHours();
  var m=today.getMinutes();
  ms = m + "";
  if (ms.length<2) ms = "0"+ms;
  stamp = h+":"+ms+" ";
  }
  chatlog.push(stamp+fmtmsg);
  if (chatlog.length > WINDOW_SCROLL) { 
  //chatlog.shift();
  document.getElementById('chat').innerHTML =chatlog.join('');
  chatlog = [];
  } else {  document.getElementById('chat').innerHTML += stamp+fmtmsg; } 
  if (lpushdown)
  document.getElementById('chat').scrollTop = document.getElementById('chat').scrollHeight;
 
}
function sendStatus(message) {
  pushdown = false;
  drx = 0;
  if (document.getElementById('status').style.pixelHeight) drx=document.getElementById('status').style.pixelHeight;
  else drx = document.getElementById('status').offsetHeight;
  if (document.getElementById('status').scrollTop >= document.getElementById('status').scrollHeight-parseInt(drx)) {
    pushdown = true;
  }
  fmtmsg = message+'';
  statuslog.push(fmtmsg);
  if (statuslog.length > WINDOW_SCROLL) { 
    //statuslog.shift();
    document.getElementById('status').innerHTML = statuslog.join('');
    statuslog = [];
  } else {
    document.getElementById('status').innerHTML += fmtmsg;  
  }
  if (pushdown)
  document.getElementById('status').scrollTop = document.getElementById('status').scrollHeight;
}
currentColor = 0;
var tableRound = 0;
function round_change(newround) {
	tableRound =  newround;
	setCurrentTableStr(JSID);
}
function clearTurnNums() {
  try {
	for (x=1;x<7;x++) {
	    document.getElementById('user'+x+'con').innerHTML='';
	    document.getElementById('user'+x+'plus').innerHTML='';
	}
  } catch (err) { handle_silently(err); }
}
tc_lastturn = 0;
tc_newturn = 0;

function tc_roster(newx) {
 if (newx==0) return;
 for (z=1;z<=6;z++) {
   if (document.getElementById("user"+z).style.display=='') {
   	document.getElementById("user"+z).className="user"+z;
   }
 }
   	document.getElementById("user"+newx).className="user"+newx+"hot";
}
function turnChange(jsidcheck,x,newx,conlands,plusdice) {
 
 if (JSID!=jsidcheck) return;
 tc_lastturn = x;
 tc_newturn = newx;
 localDepress=-1;
 gameinprogress=1;
 currentColor=newx;
 myTurn = false;
//TC_ROSTER
  tc_roster(newx);
 //document.getElementById("user"+newx).style.borderColor=colors[newx];
 //document.getElementById("user"+newx).style.borderStyle='outset';
 //document.getElementById("user"+newx).style.borderWidth='2px';
 //document.getElementById("user"+newx).style.backgroundImage='url('+STATIC_HOST+'images/dgrey.png)';

  startTimer(START_TIME);
  if (x==0 || newx==0) return;
  if (newx==myColor) { 
  playSound('startturn');
  document.getElementById('countdown').style.backgroundColor = colors[newx];
  tutorYourTurn(colors[myColor]);
  myTurn=true;
   } else {
  document.getElementById('countdown').style.backgroundColor = '#666';
    myTurn=false;
  }
  if (parseInt(conlands)>0)
    document.getElementById('user'+x+'con').innerHTML=''+conlands;
  if (plusdice>0) {
    document.getElementById('user'+x+'plus').innerHTML='+'+plusdice;
  } else 
	    document.getElementById('user'+x+'plus').innerHTML='&nbsp;';
//  sendStatus('<br><span style="color: '+colors[newx]+'"><b>'+removeHTMLTags(document.getElementById('user'+newx+'name').innerHTML)+'\'s turn </b></span><br>');
txth = document.getElementById('user'+newx+'name').innerHTML;  
if (txth=="") return;
sendStatus('<br><font style="color:'+colors[newx]+'"><b>'+txth.substring(txth.lastIndexOf(">")+1,txth.length)+'\'s turn </b></font><br>');

    for (xc = 0; xc < table_size; xc++) {
	if (rainbowG[xc]==x)
	undepress_square(xc,x );	
    }
  enableTableControls();
  flash_colors(newx);
}

function flash_colors(tc) {
	if (BOUNCE_OFF) return;
	if (OPERAWII) return;
	try {
    for (x = 0; x < table_size; x++) {
    
	if (rainbowG[x]==tc) {
	//new Effect.Highlight(''+x, {duration: 1} );
		oldcolor=$('#'+x).css('background-color');
  		$('#'+x).Highlight('slow','#FFF');
		//$('#'+x).Highlight('1',colors[x]);
		setTimeout("fc_return("+JSID+",'"+x+"','"+oldcolor+"');",700+50);	
		}
		
    }
    } catch (err) { handle_silently(err); }
}
function fc_return(temp_jsid,x,oldcolor) {
	try {
		if (temp_jsid==JSID)
  			document.getElementById(x).style.backgroundColor = oldcolor;	
  		} catch (err) {}
}
function endGame(color) {
  timeleft=0;
  myColor=0;
  playSound('endgame');
  gameinprogress=0;
  timer_seconds=0;
  clearTurnNums();
  enableTableControls();
}
function gameStart() {
  tutorGameStart();
  startTimer(START_TIME);
  tableRound = 1;
  setCurrentTableStr(JSID);
  playSound('startgame');
  whoami=0;
  localDepress=0;
  sendStatus('<span style="color: '+colors[7]+'"><b>NEW GAME</b></span><br>');
  enableTableControls();
}
function blacken(x) {
	try {
	   document.getElementById(x).innerHTML='';
	   document.getElementById(x).style.backgroundColor= '#000000';
	   document.getElementById(x).style.borderColor = '#000000';
	   document.getElementById(x).style.borderWidth = 1;
	   document.getElementById(x).style.backgroundImage = 'none';	
	} catch (err) { handle_silently(err); return; }
}
function stand() {
	//document.getElementById('chair').innerHTML = 'Stand';
}

function hidereg() {
  document.getElementById('cover').className='hidden';
  document.getElementById('register').className='hidden';
}
function hideinvite() {
  document.getElementById('cover').className='hidden';
  document.getElementById('inviteaction').className='hidden';
}
function gadc() {
 try {
 //document.getElementById('regfailed').innerHTML = '<script language="JavaScript" type="text/javascript">var google_conversion_id = 1056555049;var google_conversion_language = "en_US";var google_conversion_format = "1";var google_conversion_color = "666666";if (1) {  var google_conversion_value = 1;}var google_conversion_label = "signup";</script><script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js"></script><noscript><img height=1 width=1 border=0 src="http://www.googleadservices.com/pagead/conversion/1056555049/imp.gif?value=1&label=signup&script=0"></noscript>';
 var google_conversion_id = 1056555049;var google_conversion_language = "en_US";var google_conversion_format = "1";var google_conversion_color = "666666";if (1) {  var google_conversion_value = 1;}var google_conversion_label = "signup";
 google_handle_conversion();
 } catch (err) { handle_silently(err); }
}

function showreg() {
  bw = document.body.clientWidth;
  bh = document.body.clientHeight; 
  document.getElementById('cover').style.height=bh;
  document.getElementById('cover').style.width=bw;
  document.getElementById('cover').className='';
  document.getElementById('register').className='';
  document.getElementById('register').style.top=(bh-260)/2+'px';
  document.getElementById('register').style.left=(bw-660)/2+'px';
}
function showinvite() {
  bw = document.body.clientWidth;
  bh = document.body.clientHeight; 
  document.getElementById('cover').style.height=bh;
  document.getElementById('cover').style.width=bw;
  document.getElementById('cover').className='';
  document.getElementById('inviteaction').className='';
  document.getElementById('inviteaction').style.top=(bh-260)/2+'px';
  document.getElementById('inviteaction').style.left=(bw-660)/2+'px';
}
LOADING = false;
function showloading() {
  LOADING = true;
  bw = document.body.clientWidth;
  bh = document.body.clientHeight; 
  document.getElementById('cover').style.height=bh;
  document.getElementById('cover').style.width=bw;
  document.getElementById('cover').className='';
  document.getElementById('loading').className='';
  document.getElementById('loading').style.top=(bh-260)/2+'px';
  document.getElementById('loading').style.left=(bw-360)/2+'px';

}
function hideloading() {
    document.getElementById('cover').className='hidden';
  document.getElementById('loading').className='hidden';
}

function regfailed(reason) {
  document.getElementById('regfailed').innerHTML = 'Registraion failed.. '+reason;
}

function sendreg(username,password1,password2,email) {
  if (password1!=password2 || password2 == '') {
    regfailed('Passwords don\'t match.');
    return;
  }
  if (!check_email(email)) {
    regfailed('Email address invalid.');
    return;
  }
  Tracker.sendReg(username,password1,email);
}

function check_email(e) {
ok = 
"1234567890qwe+rtyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){ 
return (false);
}	
} 

if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) {
return (-1);		
} 

}

}

START_TIME=13;
function startTimer(seconds) {
   /*timeleft=seconds;
   if (timeleft<0) timeleft=0;
   if (gameinprogress==1 && timeleft!=START_TIME) {
   document.getElementById("countdown").style.width=timeleft*15;
   setTimeout("startTimer(--timeleft)",1000);   
   }
   if (gameinprogress==0) { gameinprogress=1;
   document.getElementById("countdown").style.width=timeleft*15;
   setTimeout("startTimer(--timeleft)",1000);   
   }
   */
   timer_seconds=seconds;
}


function startTimerOne() {
   timer_seconds--;
   if (timer_seconds<0) timer_seconds=0;
   document.getElementById("countdown").style.width=timer_seconds*15;
   document.getElementById("tbanner").style.backgroundColor = '#333';
   setTimeout("startTimerOne()",1000);   
}

function gameStartCheck() {
	if (myColor == 0) {
  		document.getElementById('gamestart_now').checked = false;
  		document.getElementById('pntxt').innerHTML = 'Play now';
  		sendStatus('You must sit first.<br>');
  		return;
	}

	if (document.getElementById('gamestart_now').checked == true) {
    	Tracker.game_start(1);
	} else {
    	Tracker.game_start(0);
	}
}

dimgc = [];
lastloaddir = "-1";
/*
dimgc0 = new Image(128,128);
dimgc1 = new Image(128,128);
dimgc2 = new Image(128,128);
dimgc3= new Image(128,128);
dimgc4= new Image(128,128);
dimgc5 = new Image(128,128);
dimgc6 = new Image(128,128);
dimgc7 = new Image(128,128);
dimgc8 = new Image(128,128);
dimgc9 = new Image(128,128);
dimgc10 = new Image(128,128);
*/
function loadImages(dir) {
	if (lastloaddir==dir) return;
	lastloaddir=dir;
   for (x=0;x<=10;x++) {
 	pic = new Image(128,128);
	pic.src=STATIC_HOST+'images/'+dir+x+'.png';
	dimgc.push(pic); 
   } 
    /*
	dimgc0.src = STATIC_HOST+'images/'+dir+0+'.png';
	dimgc1.src = STATIC_HOST+'images/'+dir+1+'.png';
	dimgc2.src = STATIC_HOST+'images/'+dir+2+'.png';
	dimgc3.src = STATIC_HOST+'images/'+dir+3+'.png';
	dimgc4.src = STATIC_HOST+'images/'+dir+4+'.png';
	dimgc5.src = STATIC_HOST+'images/'+dir+5+'.png';
	dimgc6.src = STATIC_HOST+'images/'+dir+6+'.png';
	dimgc7.src = STATIC_HOST+'images/'+dir+7+'.png';
	dimgc8.src = STATIC_HOST+'images/'+dir+8+'.png';
	dimgc9.src = STATIC_HOST+'images/'+dir+9+'.png';
	dimgc10.src = STATIC_HOST+'images/'+dir+10+'.png';
	*/
}

loadImages('');

function changeSkin(skinname) {
	if (skinName==skinname)
	return;   
	dimgc = [];
   skinName = skinname;
    dir = '';
    if (skinName!='default') dir = skinName + '/';
   loadImages(dir);
   random_color(rainbowG,diceG);
   size_controls();
}

function  displayroll(xcolor,ycolor,xnum,ynum,attackary,defendary) {
  dice_speed = 180;
  if (ycolor==0) return;
  if (IE6==1) return;
  if (roll_disp_off) return;
  var disp = document.getElementById("rolldisp");
  var disaf = document.getElementById("rollattacker");
  var disdf = document.getElementById("rolldefender");
  ct = 0;
  for (ind = 0; ind < attackary.length && ind < defendary.length; ind++) {
     if (attackary[ind]==0 || defendary[ind]==0) break;
     ct++;
  }
  width = 65+(54)*ct;
  if (ct<2)
    width = 65+(54)*ct;
  disp.style.width = width+'px';
  if (UA==0) {
   disp.style.width = (width+1*ct)+'px';
   disaf.style.width = (width+1*ct)+'px';
   disdf.style.width = (width+1*ct)+'px';
  }
  disp.style.height = '120px';
  var game_left = (document.body.clientWidth-(width))/2;
  var game_top = parseInt(document.getElementById("game").style.top);
  var game_width = document.getElementById("game").style.width;
  disaf.style.top='0px';
  disaf.style.left= '0px';
  disdf.style.top='10px';
  disdf.style.left= '0px';
  disp.style.left = game_left + 'px';
  disp.style.top = (game_top - 35)+'px';
  disp.className='';
  disp.style.opacity='0.8';
  celltop=0;
  cellleft=0;
  colnum=0;
  rownum=0;
  html_div1 = '<div class="rd" id="disa" style="float: left; cursor: pointer; width: 48px; left:'+cellleft+'px; top:'+celltop+'px; height: 48px; text-decoration:none; font-family:verdana;font-size: 15px;  z-index:2; -moz-user-select:none; ">&nbsp</div>';  
  html_div2 = '<div class="rd" id="disd" style="float: left; cursor: pointer; width: 48px; left:'+cellleft+'px; top:'+celltop+'px; height: 48px; text-decoration:none; font-family:verdana;font-size: 15px;  z-index:2; -moz-user-select:none; ">&nbsp</div>';
  disaf.innerHTML=html_div1;
  disdf.innerHTML=html_div2;
  for (ind=0;ind<ct;ind++) {
        celltop = (52+2*UA)+2*UA;
        cellleft = (colnum-1)*(52+2*UA)+2*UA;
	html_div1 += '<div  class="rdu" id="disa'+ind+'" style="float: left; cursor: pointer; width: 48px; left:'+cellleft+'px; top:'+celltop+'px; height: 48px; text-decoration:none; font-family:verdana;font-size: 15px;  z-index:2; -moz-user-select:none; ">&nbsp</div>';
	html_div2 += '<div  class="rdu" id="disd'+ind+'" style="float: left; cursor: pointer; width: 48px; left:'+cellleft+'px; top:'+(celltop)+'px; height: 48px; text-decoration:none; font-family:verdana;font-size: 15px;  z-index:2; -moz-user-select:none; ">&nbsp</div>';
	colnum++;      
  }  
  disaf.innerHTML=html_div1;
  disdf.innerHTML=html_div2;
  
  display_sd('a',xcolor,xnum,1);

  display_sd('d',ycolor,ynum,1);
  outnd = 0;
  jumper=0;
  for (ind=0;ind<ct;ind++) {
   if (ind>0) jumper=240;
   ad=attackary[ind];
   if (attackary[ind]>10) ad=10;
   dd=defendary[ind];
   if (defendary[ind]>10) dd=10;
   if (attackary[ind]>defendary[ind]) {
      ynum--; } else { xnum--; }
   setTimeout("display_group("+ind+","+xcolor+","+ycolor+","+ad+","+dd+","+xnum+","+ynum+");",dice_speed*ind+jumper);
   outnd=ind*dice_speed+jumper;
  }

  if (outnd<1000) outnd=1000;
  setTimeout("document.getElementById('rolldisp').className='hidden';",outnd+jumper);
}
function display_group(ind,xcolor,ycolor,ad,dd,xnum,ynum) {
   if (xnum=='' || xnum == null ) xnum=0;
   if (ynum=='' || ynum == null) ynum=0;
   display_sd('a'+ind,colors[0],ad,0);
   display_sd('d'+ind,colors[0],dd,0);
   display_sd('a',xcolor,xnum,1);
   display_sd('d',ycolor,ynum,1);
}

function dTransition(divid,fromdice,todice) {
  step=1;
  ct2=0;
  if (IE6==1 || noTransition) {
    dImg(divid,todice);
    return;
  }
  if (fromdice>todice) step=-1;
  else if (fromdice==todice) return;
  for (ct = fromdice; ct != todice +step; ct+=step) {
    ct2++;
   setTimeout("dImg("+divid+","+ct+");",82*ct2);
  }

}

function display_sd(ind, color, num, dieface) {
   var die = document.getElementById('dis'+ind);
   if (die!=null) {
   die.style.backgroundColor = colors[color];
   if (num==0) { die.innerHTML=""; die.style.backgroundColor='#000000'; return; }
    dir = '';
    if (skinName!='default') dir = skinName + '/';
   if (dieface==1)
   die.innerHTML = '<img height=48 width=48 src='+STATIC_HOST+'images/'+dir+num+'.png>';
   else 
   die.innerHTML = '<img height=48 width=48 src='+STATIC_HOST+'images/dice/'+num+'.png>';
   }
}

function set_mute(person) {
	if (is_muted(person) == true)
		return;
		
	muted.push(person);
		
	// Look for person in chairs
	for (i = 0; i < local_chairs.length; i++) {
		if (local_chairs[i] == person) {
			set_chair_mute(i + 1);
			return;
		}
	}
		
	// Look for person in watchers
	for (i = 0; i < local_watchers.length; i++) {
		if (local_watchers[i] == person) {
			set_watcher_mute(i);
		}
	}
}

function unset_mute(person) {
	for (j = 0; j < muted.length; j++) {
    	if (person == muted[j]) {
    		muted.splice(j, 1);
		
			// Look for person in chairs
			for (i = 0; i < local_chairs.length; i++) {
				if (local_chairs[i] == person) {
					unset_chair_mute(i + 1);
					return;
				}
			}
		
			// Look for person in watchers
			for (i = 0; i < local_watchers.length; i++) {
				if (local_watchers[i] == person) {
					unset_watcher_mute(i);
					return;
				}
			}
		}
	}
}

function ChatMessage(msg) {
  ary = msg.split(":");
  if (ary[0]=="/creategame") { showcreate(); }
  else if (ary[0]=="/vfxoff") { IE6=1;  random_color(rainbowG,diceG); return; }
  else if (ary[0]=="/vfxon") { IE6=0;   draw_map(TNAME,JSID); random_color(rainbowG,diceG); return; }
  else if (ary[0]=="/tmon") { timeStamp = true; }
  else if (ary[0]=="/tmoff") { timeStamp= false; }
  else if (ary[0]=="/dton") { noTransition=false; }
  else if (ary[0]=="/dtoff") { noTransition=true; }
  else if (ary[0]=="/uocon") { undepressOwnColor=true; }
  else if (ary[0]=="/uocff") { undepressOwnColor=false; }
  else if (ary[0]=="/jqon") { BOUNCE_OFF=false; }
  else if (ary[0]=="/jqoff") { BOUNCE_OFF=true; }
  else if (ary[0]=="/klaon") { keepLastAttack=true; }
  else if (ary[0]=="/klaoff") { keepLastAttack=false; }
  else if (ary[0]=="/rdoff") { roll_disp_off=true; return; }
  else if (ary[0]=="/rdon") { roll_disp_off=false; return; }
  else if (ary[0]=="/sfxoff") { sound_effects_off=true; return; }
  else if (ary[0]=="/sfxon") { sound_effects_off=false; return; }
  else if (ary[0]=='/mute') { person = ary[1]; set_mute(person); sendChat(person + ' is muted.<br>'); return; }
  else if (ary[0]=='/msg' || ary[0] == '/m') { sendChat('<span class="privmsg"> --> ' + msg.substring(ary[0].length + 1, msg.length)+'</span><br>'); }
  else if (ary[0]=='/silentmsg') { }
  else if (ary[0]=='/unmute')  { person = ary[1]; unset_mute(person); sendChat(person + ' is unmuted.<br>'); return; }
  
  if (msg == lastMessage && !(msg.substring(0,1)=='!' || msg.substring(0,1)=='/')) return;
  lastMessage=msg;
  
  Tracker.ChatMessage(msg);
 
}

function removeHTMLTags(strInputCode){
	return strInputCode.replace(/<\/?[^>]+(>|$)/g, "");	
}

function satout(seat) {
 try {
  ob = document.getElementById('sat'+seat);
  ob.innerHTML = '<img src="images/satout.gif">';
  ob.className = 'sats';
  setTimeout('document.getElementById("sat'+seat+'").className="hidden"',3000); 
  } catch (err) { handle_silently(err); }
}
function satin(seat) {
  try {
  ob = document.getElementById('sat'+seat);
  ob.innerHTML = '<img src="images/satin.gif">';
  ob.className = 'sats';
  setTimeout('document.getElementById("sat'+seat+'").className="hidden"',3000); 
  } catch (err) { handle_silently(err); }
}
function createTableTip(paramstr) {
	values = paramstr.split(':');
   
	if (values[4] == 1)
		pvstr = 'Partial victory';
	else
		pvstr = 'All or nothing';
		
	if (values[5] > 0)
		tmov = 'Offturn: ' + values[5] + '/' + values[6];
	else
		tmov = 'No Offturn';
		
	return 'Size: '+ values[0] + ' x ' + values[1] + ' - ' + pvstr + ' - ' + tmov;
}

function createTableInfo(paramstr) {   
	values = paramstr.split(':');
   	round_str = '';
	//round_str = '<div id="round"></div><br>';
	if (tableRound>0) round_str = 'Round: '+tableRound+' ';
	if (values[4] == 1)
		pvstr = 'Partial victory';
	else
		pvstr = 'All or nothing';
		
	if (values[5] > 0)
		tmov = 'Offturn: ' + values[5] + '/' + values[6];
	else
		tmov = 'No Offturn';
		
	author_str = '<br>';
	if (values[2].length > 0)
		if (values[2]!=null)
		author_str = ' | Author: ' + values[2] + '<br>'; 
	
	return '<center>' + round_str + author_str + 'Dice cap: ' + values[3] + ' | ' + pvstr + '<br>' + tmov  +'</center>';
}
function createTableInfo2(paramstr) {   
	values = paramstr.split(':');
   	round_str = '';
	//round_str = '<div id="round"></div><br>';
	if (values[4] == 1)
		pvstr = 'Partial victory';
	else
		pvstr = 'All or nothing';
		
	if (values[5] > 0)
		tmov = 'Offturn: ' + values[5] + '/' + values[6];
	else
		tmov = 'No Offturn';

	return '<center>Dice cap: ' + values[3] + ' | ' + pvstr + '<br>' + tmov  +'</center>';
}

function pushchatlog(tt) {
 try {
 receivechatlog(tt);
 } catch (err) {}
}
function createmap() {
	//alert(document.getElementById('omaps').value);
	ofriends = "false";
	if (document.getElementById('omapfriends').checked)
		ofriends="true";
	tableid= document.getElementById('tableslist').options[ document.getElementById('tableslist').options.selectedIndex].value;
	Tracker.createMap(document.getElementById('omaps').value, document.getElementById('onumop').value,ofriends,tableid);
	hidecreate();
}
tablesLoaded = false;
function showcreate() {
  bw = document.body.clientWidth;
  bh = document.body.clientHeight; 
  document.getElementById('cover').style.height=bh;
  document.getElementById('cover').style.width=bw;
  document.getElementById('cover').className='';
  if (!tablesLoaded) {
  	load_tables('false:false');
  	tablesLoaded=true;
  	}
  document.getElementById('creategame').className='';
  document.getElementById('creategame').style.top=(bh-140)/2+'px';
  document.getElementById('creategame').style.left=(bw-400)/2+'px';
}
function hidecreate() {
  document.getElementById('cover').className='hidden';
  document.getElementById('creategame').className='hidden';
}

function send_invite(email) {
  if (check_email(email)) {
	  Tracker.sendInvite(email);
  }
	document.getElementById('iemail').value='';
}
function send_friend_req(name) {
  Tracker.sendFriendReq(name);
  document.getElementById('iname').value='';
  
}


function load_tables(check_boxes_values) {
        Tracker.getTablesForPrivate( check_boxes_values, {
                callback:function(str) {
                        if (str == null)
                                alert("Unable to retrieve user tables.  Please make sure you are logged in.");
                        else {
                                // Reset the list
                                var tableslist = document.getElementById('tableslist');
                                tableslist.options.length = 1;

                                if (str.length > 1) {
                                		str+=";::";  //blank table
                                        var values1 = str.split(";");

                                        // Add table names
                                        for (i = 0; i < values1.length; i++) {
                                                var values2 = values1[i].split(":");
                                                // Set value to be the concatanated string of parameters
                                                tableslist.options[tableslist.options.length] = new Option(values2[1], values2[2]);
                                        }
                                }
                        }
                }
        });
}
